apiready = function(){
seajs.use(['../../V',"../../api","../../jquery","../../app","../../service","../../swiper"],function(V,$api,$,app,service,Swiper){
  var el = document.querySelector('.container');
  var vm = {
    el: el,
    data: {
      type: '',
      page: 1,
      goodsList: [], // 商品列表
      hasMoreData: true,
      userInfo: '', // 获取用户身份
    },
    created: function () {
      var that = this;
      if($api.getStorage("user")){
        this.userInfo = $api.getStorage("user").data;
      }


      this.type = api.pageParam.type;
      this.init();

      // 触底
      api.addEventListener({
          name: 'scrolltobottom',
          extra:{
              threshold:0
          }
      }, function(ret, err){
          that.scrolltobottom();
      });

      // 下拉刷新
      app.refreshHeaderInfo(function () {
        that.page = 1;
        that.goodsList = [];
        that.getGoodsList();
      });
    },
    methods: {
      init: function () {
        var title = document.querySelector('.wrapper .title');
        var type = this.type;
        if (type == 2 ) {
          // 品牌清仓
          title.innerText = '品牌清仓';
        } else if (type == 3) {
          // 名品打折
          title.innerText = '名品折扣';
        } else if (type == 4) {
          // 9块9特卖
          title.innerText = '9块9特卖';
        }
        this.getGoodsList();
      },

      // 获取商品列表
      getGoodsList: function () {
        var that = this;
        app.ajax(
          service['indexTagGoods'],
          {
            data: {
              values: {
                tag: that.type,
                page: that.page
              }
            }
          },
          function (res) {
            if (res.code == 0) {
              if (res.data.list.length > 0) {
                $('.no-goods').hide();
                for (var i = 0, len = res.data.list.length; i < len; i++) {
                  that.goodsList.push(res.data.list[i]);
                }
                that.hasMoreData = true;
              } else {
                that.hasMoreData = false;
                if (that.page == 1) {
                  $('.no-goods').show();
                }
                api.toast({
                    msg: '没有更多数据了',
                    duration: 2000,
                    location: 'bottom'
                });
              }
            } else {
              api.toast({
                  msg: res.message,
                  duration: 2000,
                  location: 'bottom'
              });
            }
          }
        );
      },

      // 前往详情
      toDetail: function (id, is_group) {
        if (is_group) {
          // 拼团商品
          app.openWin('groupBuyDetail',{goodsId: id});
        } else {
          // 普通商品
          app.openWin('buyGoods',{goodsId: id});
        }
      },

      // 加载更多
      scrolltobottom: function () {
        if (this.hasMoreData) {
          this.page += 1;
          this.getGoodsList();
        }
      }
    }
  }
  var even = function() {}
  var newVue = new Vue(vm);
  even();
});
}
